import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Map,Bar,Grid
from pyecharts.faker import Faker

data = pd.read_csv('end.csv')

# 因为有些数据中有仅含有长沙的数据所以我们将数据进行切分成两个
data[['地区','区']] = data['地区'].str.split('-',expand=True)
#print(data)

# 统计区的数据
data = data['地区'].groupby(data['区']).value_counts()

# print(data)

areas = []
values = []

for key,value in zip(data.keys(),data.values):
    # print(key[0])
    # print(value)
    if key[1] == '长沙':
        areas.append(key[0].strip())
        values.append(int(value))

# map = Map()
# map.add("招聘人数", [list(z) for z in zip(areas, values)], "长沙")
# map.set_global_opts(title_opts=opts.TitleOpts(title="长沙地图"),
# visualmap_opts=opts.VisualMapOpts(max_=100, is_piecewise=True),tooltip_opts=opts.TooltipOpts(is_show=True))
# map.render(path = '长沙地图1.html')
map = (
        Map(init_opts=opts.InitOpts(
                                width='1400px',
                                height='600px',
        ))
        .add("招聘人数", [list(z) for z in zip(areas, values)], "长沙")
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title=  "招聘数据可视化",
                subtitle="",
                pos_left="center",
                pos_top="top"
                ),
            legend_opts=opts.LegendOpts(pos_left="20%"),
            visualmap_opts=opts.VisualMapOpts(
                is_piecewise=True,
                dimension=0,
                pos_left="50",
                pos_top="center",
                range_color=["lightskyblue", "yellow", "orangered"],
                textstyle_opts=opts.TextStyleOpts(color="#000"),
            ),
        )
    )

bar = (
    Bar(init_opts=opts.InitOpts(
                                width='800px',
                                height='400px',
        ))
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values())
    .add_yaxis("商家B", Faker.values())
    .reversal_axis()
    .set_series_opts(label_opts=opts.LabelOpts(position="right"))
    # .render("bar_reversal_axis.html")
)
grid = (
    Grid()
        .add(map, grid_opts=opts.GridOpts(pos_left="60%",pos_bottom="80%"))
    .render("grid_vertical.html")
)





